#include "ipc_event_util.h"
#include <string.h>
#include <arpa/inet.h>

using namespace ipc_event;

/*
 *******************************************************************************
 *
 * @param Implementation Notes:
 *        None.
 *
 *******************************************************************************
 */
int IPCMsgUtils::compile(char * buffer , int offset , int value , int length)
{
  uint32_t data  = htonl((uint32_t)value);
  
  (void)memcpy(buffer + offset , (void*)&data ,sizeof(data));
  
  return length;
}

/*
 *******************************************************************************
 *
 * @param Implementation Notes:
 *        None.
 *
 *******************************************************************************
 */
int IPCMsgUtils::compile(char * buffer , int offset , short value , int length)
{
  uint16_t data = htons((uint16_t)value);
  
  (void)memcpy(buffer + offset , (void*)&data , sizeof(data));
  
  return length;
}

/*
 *******************************************************************************
 *
 * @param Implementation Notes:
 *        None.
 *
 *******************************************************************************
 */
int IPCMsgUtils::compile(char * buffer , int offset , void * data , int length)
{
  (void)memcpy(buffer + offset , data , (unsigned int)length);
  
  return length;
}

/*
 *******************************************************************************
 *
 * @param Implementation Notes:
 *        None.
 *
 *******************************************************************************
 */
int IPCMsgUtils::parse(char * buffer , int offset , int & value , int length)
{	
  (void)memcpy(&value , buffer + offset , (unsigned int)length);
  
  value = ntohl(value);
  
  return length;
}

/*
 *******************************************************************************
 *
 * @param Implementation Notes:
 *        None.
 *
 *******************************************************************************
 */
int IPCMsgUtils::parse(char * buffer , int offset , short & value , int length)
{
  (void)memcpy(&value , buffer + offset , (unsigned int)length);
  
  value = ntohs(value);	
  
  return length;
}

/*
 *******************************************************************************
 *
 * @param Implementation Notes:
 *        None.
 *
 *******************************************************************************
 */
int IPCMsgUtils::parse(char * buffer , int offset , void * data , int length)
{
  (void)memcpy(data , buffer + offset , (unsigned int)length);
  
  return length;
}


